/************************************************************************/
// Copyright (C) 2016, han_gangbiao. All rights reserved.
// Use of this source code is governed by a GPL-v2 license that can be found in the License file.
// 
// [Time]:      2016-1-4 21:53:17
// [Author]:    han_gangbiao [http://my.oschina.net/jackhen]
// [Info]:      
/************************************************************************/

#ifndef INCLUDE_NET_NETINSIDE_SOCKBASE_H_
#define INCLUDE_NET_NETINSIDE_SOCKBASE_H_

#include "netaddr.h"

class sockbase_t
{
public:
	bool is_valid() const;
	int get_sockfd() const;
	void set_sockfd( int sockfd );

	int get_sock_type() const;
	void set_sock_type( int socktype );

	int get_local_addr( netaddr_t& local ) const;
	int get_remote_addr( netaddr_t& remote ) const;

	int close();
	int open( int protocol_family, int type, int protocol, bool reuse_addr );

	int set_option( int level, int optname, const char* optval, int optlen );
	int get_option( int level, int optname, char* optval, int* optlen );

	int set_sock_recv_buf( int len );
	int get_sock_recv_buf();
	int set_sock_send_buf( int len );
	int get_sock_send_buf();

	int set_nonblock();
	int set_addr_reuse();

protected:
	sockbase_t();
	sockbase_t( int type, int protocol_family, int protocol = 0, bool reuse_addr = false );
	virtual ~sockbase_t();

protected:
	int m_sockfd;
	int m_socktype;
};

#endif //~INCLUDE_NET_NETINSIDE_SOCKBASE_H_
